package com.jmu.Shape;

import java.util.Objects;

public class Rectangle extends Shape {
    /**
     * 长方形的类
     * 有对应的 setter/getter方法 以及获得周长、面积的方法
     */

    private double lenght = 0;
    private double wide = 0;

    //初始化 长 宽
    public Rectangle(double lenght, double wide) {
        this.lenght =lenght;
        this.wide = wide;
    }

    //一大堆getter/setter方法
    public double getLenght() {
        return lenght;
    }

    public double getWide() {
        return wide;
    }

    public void setLenght(double lenght) {
        this.lenght = lenght;
    }

    public void setWide(double wide) {
        this.wide = wide;
    }

    //重写获得周长、面积的方法
    @Override
    public double getPerimeter() {
        return 2.0 * (lenght + wide);
    }

    @Override
    public double getArea() {
        return lenght * wide;
    }

    //equals
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Rectangle rectangle = (Rectangle) o;
        return Double.compare(rectangle.lenght, lenght) == 0 &&
                Double.compare(rectangle.wide, wide) == 0;
    }

    //hashCode
    @Override
    public int hashCode() {
        return Objects.hash(lenght, wide);
    }
}
